<style lang="scss">
  @import 'index';
</style>

<template>
  <div class="ga-container">
    <div class="ga-tickets">

      <div class="item" v-for="(item,index) in ticketslist" :key="index"  @click="getcoupon(item.user_coupon_id)">
        <div class="box1">
          <p class="p1">
            ¥
            <span>{{item.coupon_amount}}</span>
          </p>
          <p class="p2">{{item.enable_amount>0?'单笔订单满'+item.enable_amount+'元':'无门槛使用'}}</p>
        </div>
        <div class="box2">
          <p class="p1">{{item.coupon_name}}</p>
          <p class="p2">{{item.coupon_starttime}}至{{item.coupon_endtime}}</p>
        </div>
      </div>

      <!-- <a href="/pages/rule/main" class="rule-box">
        <i class="gaIcon wh"></i>
        <span>优惠券说明</span>
      </a> -->

    </div>
  </div>
</template>

<script>
import {isLogin} from '@/utils/handleLogin'
export default {

  data () {
    return {
       ticketslist: [],
    }
  },
  onShow () {
     isLogin(() => {
      console.log(this.$root.$mp.query)
         this.load()
     })
  },
  methods: {
    /*异步加载数据*/
     async load () {
      // this.$_util.ajax.get('https://guo-a.com/mapi/ticket/couponlist?token=' + this.$store.state.Token).then((res) => {
      //   if(res.code === 200){
      //     this.ticketslist = res.data
      //   }
      // })
      let params = {
        data: decodeURIComponent(this.$root.$mp.query.data)
      }
      this.$_util.ajax.post('https://guo-a.com/mapi/order/use_coupon_list?token=' + this.$store.state.Token,params).then((res)=>{
        console.log(res)
        if(res.code === 200){
          this.ticketslist = res.data
        }
      })
     },
     /*点击领取优惠券*/
     async getcoupon(id){
      let pages = getCurrentPages();//当前页面
      let prevPage = pages[pages.length-2];//上一页面
      console.log(prevPage)
      prevPage.setData({
        coupon_id: id
      });
      wx.navigateBack()
      // return false
      //     wx.navigateTo({
      //         url: '/pages/order/main?data=' + this.$root.$mp.query.data + '&coupon_id=' + id
      //     })
      // console.log('选择优惠券')
     }
  }
  
}
</script>
